package com.cjm.one.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjm.one.common.result.Result;
import com.cjm.one.model.system.entity.SysResource;
import com.cjm.one.model.system.vo.SysResourceVo;
import com.cjm.one.system.mapper.SysResourceMapper;
import com.cjm.one.system.service.SysResourceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "系统菜单管理")
@RequestMapping("/admin/system/menu")
public class SysMenuController {
    @Resource
    private SysResourceService sysResourceService;

    @PostMapping("/list")
    @Operation(summary = "查询菜单树状列表")
    public Result<List<SysResourceVo>> list(@RequestBody SysResource sysResource) {
        List<SysResourceVo>  result = sysResourceService.selectListPage(sysResource);
        return Result.ok(result) ;
    }
    @PutMapping
    @Operation(summary = "修改菜单")
    public Result<Boolean> update(@RequestBody SysResource sysResource) {
        log.info("修改菜单:{}",sysResource);
      return   Result.ok(sysResourceService.updateById(sysResource));
    }
    @PostMapping
    @Operation(summary = "添加菜单")
    public Result<Boolean> add(@RequestBody SysResource sysResource) {
        log.info("添加菜单:{}",sysResource);
        return   Result.ok(sysResourceService.save(sysResource));
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除菜单")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        log.info("删除菜单:{}",id);
        return   Result.ok(sysResourceService.removeByIdSysResource(id));
    }
    @GetMapping("/{id}")
    @Operation(summary = "根据id获取菜单")
    public Result<SysResource> getById(@PathVariable("id") Long id) {
        return   Result.ok(sysResourceService.getById(id));
    }
}
